package com.xw.class03;

/**
 * @author: xw
 * @create: 2022/9/8 14:24
 * @description:移除链表的指定的值
 */
public class Code02_RemoveNum {
    public static class Node {
        public int value;
        public Node next;

        public Node(int data) {
            this.value = data;
        }
    }

    public static Node removeValue(Node head,int num){
        //head来到第一个不要删除的未
        while(null != head){
            if(num == head.value){
                break;
            }
            head = head.next;
        }
        Node pre = head;
        Node cur = head;
        while(null != cur){
            if(cur.value == num){
                pre.next = cur.next;
            }else{
                pre = cur;
            }
            cur = cur.next;
        }
        return head;
    }
}
